<?php
	$user = $controller->getCurrentUser();	
	//on verifie les permissions
	if ($user->isAllowedTo(GRADE_MOD_BOOK))
	{    
	
		$albumId = $request->getParam('albumId');
		
		$book = new book();
		$edition = new edition();
		$album = album::singleton($albumId);
		
		$book->setEditionObject($edition);
		$book->setAlbumObject($album);
		
		if (($publisherId = $request->getParam('publisherId')) && isset($publisherId) && is_numeric($publisherId))  $book->setIdpublisher($publisherId);
		if ($description = $request->getParam('bookDescription'))                                                   $book->setDescription($description);
		if (($price = $request->getParam('bookPrice')) && isset($price) && is_numeric($price))                      $book->setPrice($price);
		if ($year = $request->getParam('bookYear'))                                                                 $book->setYear($year);
		if ($EAN13 = $request->getParam('bookEAN13'))                                                               $book->setEan13($EAN13);
		if ($emplacement = $request->getParam('bookEmplacement'))                                                   $book->setLocation($emplacement);
		if ($cotation = $request->getParam('bookCotation'))                                                         $book->setCotation($cotation);
		if ($condition = $request->getParam('bookCondition'))                                                        $book->setCondition($condition);
		
		if ($book->isReadyToAdd() && $albumId && is_numeric($albumId))
		{
			$book->add($albumId);
			$controller->addInformation('L\'album a bien &eacute;t&eacute; enregistr&eacute; !');
			$logPermAction = 'BD ajout&eacute;e  : '.addslashes($book->getName());
			logPermactions($user->getId(), $logPermAction);
		}
		else
			$controller->addError('Veuillez remplir les champs necessaires !');    

		$request->clean('post');
		$controller->forward('addBook');
	}  
	else
		$controller->render('errorRights');
  
?>
